#version 140

uniform vec4 instance_positions[512];
in vec4 vertices;
in vec4 texcoords;

uniform mat4 matrix_projection;
uniform mat4 matrix_world;
uniform mat4 matrix_view;

uniform mat4 matrix_shadow0;
uniform mat4 matrix_shadow1;
uniform mat4 matrix_shadow2;

uniform vec4	wind;
uniform float	time;


out vec4 pos[3];
out vec2 texCoord;

void main(void)
{
	vec4 instance_position = instance_positions[gl_InstanceID];

	float timeVal = cos (time + instance_position.w) + 0.5;
	vec3 v = vertices.xyz + vec3 (wind.xy * wind.w * timeVal, 0.0) * vertices.z;

	vec4 global_pos = vec4 (v + instance_position.xyz, 1.0);
	global_pos = matrix_world * global_pos;
	pos[0] = matrix_shadow0 * global_pos;
	pos[1] = matrix_shadow1 * global_pos;
	pos[2] = matrix_shadow2 * global_pos;

	texCoord = texcoords.xy;

	gl_Position = matrix_projection * matrix_view * global_pos;
}
